/*
 * Copyright (C) 2011, EADS France
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 */
package xowl.gmi.view;

/**
 *
 * @author Laurent WOUTERS
 */
public class ToolboxElementDragable extends ToolboxElement {
    public static interface Actions {
        java.awt.datatransfer.DataFlavor getFlavor();
        Object getData();
    }
    
    private Actions actions;
    
    public ToolboxElementDragable(Actions acts, String description, ViewStyle style) {
        super(description, style);
        this.actions = acts;
        
        DragHandler dragHandler = new DragHandler() {
            @Override public int getAction() { return javax.swing.TransferHandler.COPY; }
            @Override public Object getTransferable() { return actions.getData(); }
            @Override public java.awt.datatransfer.DataFlavor getDataFlavor() { return actions.getFlavor(); }
            @Override public java.awt.Image getImage() { return null; }
            @Override public void onDragStart(java.awt.Point location) {
                isHovered = false;
                ToolboxElementDragable.this.repaint();
            }
            @Override public void onDragDropEnd(Object transfered, int action) { }
        };
        DragDropUtil.setTarget(this, dragHandler, null);
        DragDropUtil.setTarget(label, dragHandler, null);
    }
}
